<!--事前查验组件-->
<template>
    <div style="text-align:center;overflow:auto;vertical-align: middle;height: 50%">
        <Table :row-class-name="rowClassName" :loading="Loading" id="table"
               size="small"
               :columns="columns1"
               :data="data1"
        ></Table>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'

    export default {
        name: 'Ss00011Check',
        props: {
            ssca0002: {
                //type: String,
                required: false
            },
            ssca0016: {
                required: false
            },
            azcp0001: {
                type: String,
                required: false
            },
            azcp0003: {
                type: String,
                required: false
            },
            ss12001Id: {
                type: String,
                required: false
            },
            ss17001Id: {
                type: String,
                required: false
            },
            ss11001Id: {
                type: String,
                required: false
            },
            ss17002Id: {
                type: String,
                required: false
            },
            ss11002Id: {
                type: String,
                required: false
            }, isPushData: {
                type: String,
                required: false
            }, isFpPerson: {
                type: String,
                required: false
            }
            //入参：是否请求后台
            , isRequestBackstage: {
                type: Boolean,
                required: false
            },
            azcp0595:{
                type: String
            },
            azcp0596:{
                type: String
            },
            azcp0597:{
                type: String
            },
            azcp0598:{
                type: String
            },
            azcp0599:{
                type: String
            },
            azcp0600:{
                type: String
            }
        },
        data() {
            return {
                Loading: false,
                validateInfo: 'success', //返回父组件的验证信息
                validateStatus: true, //返回父组件的验证信息标识-父组件的下一步disabled属性
                batchNumber: '', //批次号
                responSign: 0,//请求的总数，=11 说明全部请求完毕，回显组件
                spinShow: true,
                tableShow: false,
                columns1: [
                    {
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '查验类别',
                        key: 'type',
                        align: 'center',
                    },
                    {
                        title: '验证结果',
                        key: 'msg',
                        align: 'center',
                        render: (h, params) => {
                            let value = params.row.msg
                            return h('div', value + ' ')
                        }
                    }
                ],
                data1: [],
                dataMap: new Map(),
            }
        },
        watch: {
            //是否请求后台
            isRequestBackstage(newvalue, oldvalue) {
                if (newvalue == true) {
                    this.Loading = true;
                    this.spinShow = true;
                    this.tableShow = false;
                    this.data1 = []; //table 数据
                    this.dataMap = new Map();
                    this.responSign = 0; //响应总数标识
                    this.validateInfo = 'success';
                    this.validateStatus = true;
                    //获取当前时间戳，作为批次号请求后台
                    let timestamp = Date.parse(new Date());
                    Promise.all([
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "000", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "100", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "200", timestamp)
                        }),
                        // new Promise((resolve, reject) => {
                        //     //清除无效数据
                        //     this.saveValidateData(resolve, "300", timestamp)
                        // }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "400", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "500", timestamp)
                        }),
                        // new Promise((resolve, reject) => {
                        //     //清除无效数据
                        //     this.saveValidateData(resolve, "600", timestamp)
                        // }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "700", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "800", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "900", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "1000", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "1100", timestamp)
                        }),
                        new Promise((resolve, reject) => {
                            //清除无效数据
                            this.saveValidateData(resolve, "1200", timestamp)
                        }),
                      new Promise((resolve, reject) => {
                        this.saveValidateData(resolve, "3300", timestamp)
                      }),
                      new Promise((resolve, reject) => {
                        //供养遗属 验证
                        this.saveValidateData(resolve, "3400", timestamp)
                      }),
                      new Promise((resolve, reject) => {
                        //知青救助
                        this.saveValidateData(resolve, "3500", timestamp)
                      }),

                    ]).then(res => {
                        this.Loading = false;
                        //返回给父组件批次号
                        this.$emit("update:batchNumber", this.batchNumber)
                        //返回给父组件异常信息
                        this.$emit("update:validateInfo", this.validateInfo)
                        if (this.validateInfo === 'success') {
                            this.validateStatus = false; //验证通过，下一步可用
                        }
                        this.$emit("update:validateStatus", this.validateStatus)
                        this.$emit("update:checkBtnName", "人员信息(已查验)")
                        //数据置空
                        this.data1 = [];
                        //map转数组
                        let arrayObj = Array.from(this.dataMap);
                        //按key排序
                        arrayObj.sort(function (a, b) {
                            //map转成array后，下标0为key，下标1为value
                            //a[0]-b[0] 升序
                            //b[0]-a[0] 降序
                            return a[0] - b[0];
                        });
                        //转换为map
                        let resultMap = new Map(arrayObj.map(i => [i[0], i[1]]));

                        //遍历 data1
                        for (let value of resultMap.values()) {
                            this.data1.push(value)
                        }
                        //请求后台，获取this.batchNumber批次号，残疾人信息，
                        var cjrParam = {
                            batchNumber: this.batchNumber,
                        }
                        postAction('/api/ac/subsistence/ss00011Service/getCjrInterfaceInfo', cjrParam).then((res) => {
                            this.$emit("update:azcp0503", res.data.data.azcp0503)
                            this.$emit("update:azcp0579", res.data.data.azcp0579)
                            this.$emit("update:azcp0580", res.data.data.azcp0580)
                            this.$emit("update:azcp0587", res.data.data.azcp0587)
                            this.$emit("update:azcp0591", res.data.data.azcp0591)
                            if (res.data.data.azcp0503 == '1') {
                                this.$emit("update:azcp0504", res.data.data.azcp0504)
                                this.$emit("update:azcp0505", res.data.data.azcp0505)
                                if (res.data.data.azcp0504=='67'){
                                    this.$emit("update:azcp0595", res.data.data.azcp0595)
                                    this.$emit("update:azcp0596", res.data.data.azcp0596)
                                    this.$emit("update:azcp0597", res.data.data.azcp0597)
                                    this.$emit("update:azcp0598", res.data.data.azcp0598)
                                    this.$emit("update:azcp0599", res.data.data.azcp0599)
                                    this.$emit("update:azcp0600", res.data.data.azcp0600)
                                }
                            } else {
                                this.$emit("update:azcp0504", '')
                                this.$emit("update:azcp0505", '')
                            }
                        }).finally(() => {
                        });

                    })
                    //时间戳=批次号
                    this.batchNumber = timestamp;
                }
            },
            responSign(newvalue, oldvalue) {
            }
        },
        methods: {
            rowClassName(row, index) {
                if (row.code == '2'|| row.msg == '非沈阳户籍'||row.msg.indexOf("疑似重复申请保障")!= -1) {
                    //异常状态：修改css
                    return 'demo-table-error-row';
                }
                return '';
            },
            //获取事前查验数据
            saveValidateData(resolve, type, timestampParam) {
                var that = this;
                //请求参数
                var dataParam = {
                    ssca0002: that.ssca0002,
                    ssca0016: that.ssca0016,
                    azcp0001: that.azcp0001,
                    azcp0003: that.azcp0003,
                    ss12001Id: that.ss12001Id,
                    ss17001Id: that.ss17001Id,
                    ss11001Id: that.ss11001Id,
                    ss17002Id: that.ss17002Id,
                    ss11002Id: that.ss11002Id,
                    isPushData: that.isPushData,
                    isFpPerson: that.isFpPerson,
                    type: type,
                    timestamp: timestampParam,
                }
                postAction('/api/ac/subsistence/ss00011Service/saveValidateData', dataParam).then((res) => {
                    for (let i in res.data.data.data) {
                        if (res.data.data.data[i].timestamp == timestampParam) {
                            //前后台的批次号（时间戳）相同 ，才push数据
                            let sortCode = res.data.data.data[i].sortCode;
                            that.dataMap.set(sortCode, res.data.data.data[i])

                            //户籍地址 type=100
                            if (type === "100" && res.data.data.data[i].azdf0500 != '' && res.data.data.data[i].azdf0500 != undefined) {
                                // alert("户籍地址："+res.data.data.data[i].azdf0500);
                                this.$emit("update:azdf0500", res.data.data.data[i].azdf0500)
                                this.$emit("update:azdf0500Disable", true);
                            }
                        }
                        //新申请事前查验不通过不允许继续办理
                        if(that.ssca0016=='100'){
                          if (res.data.data.data[i].code == '2') {
                            //获取异常信息，用于父组件（不允许下一步）
                            this.validateInfo = res.data.data.data[i].msg;
                          }
                        }else{
                        //其他业务查验事前查验除重复保障外其他查验不通过也不直接不允许办理，在第二步完成时统一校验，解决户主查验不通过不能办理业务同时还无法更换户主问题
                            if(type=='200'){
                              if (res.data.data.data[i].code == '2') {
                                //获取异常信息，用于父组件（不允许下一步）
                                this.validateInfo = res.data.data.data[i].msg;
                              }
                            }
                        }
                    }
                }).finally(() => {
                    resolve(1);
                });
            },
        }
        , created() {

        }
    }
</script>
<style scoped>
    /deep/ .demo-spin-icon-load {
        animation: ani-demo-spin 1s linear infinite;
    }

    #table{
        min-height: 400px;
    }

    @keyframes ani-demo-spin {
        from {
            transform: rotate(0deg);
        }
        50% {
            transform: rotate(180deg);
        }
        to {
            transform: rotate(360deg);
        }
    }

    /deep/ .demo-spin-col {
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }

    /deep/ .ivu-table .demo-table-info-row td {
        background-color: #2db7f5;
        color: #fff;
    }

    /deep/ .ivu-table .demo-table-error-row td {
        background-color: #ff6600;
        color: #fff;
    }

    /deep/ .ivu-table td.demo-table-info-column {
        background-color: #2db7f5;
        color: #fff;
    }

    /deep/ .ivu-table .demo-table-info-cell-name {
        background-color: #2db7f5;
        color: #fff;
    }

    /deep/ .ivu-table .demo-table-info-cell-age {
        background-color: #ff6600;
        color: #fff;
    }

    /deep/ .ivu-table .demo-table-info-cell-address {
        background-color: #187;
        color: #fff;
    }

    /deep/ tbody .ivu-table-cell {
        font-size: 16px;
    }
</style>
